package com.ruijie.autotest.log.impl.data;

import com.ruijie.autotest.log.core.data.ITable;

import java.util.ArrayList;
import java.util.List;

public class SimpleTable implements ITable {

	private final List<ColumnDrivenRow> rows;

	private final Columns columns;

	public SimpleTable(Columns columns, List<ColumnDrivenRow> rows) {
		this.rows = rows;
		this.columns = columns;
	}

	@Override
	public ColumnDrivenRow getRow(int rowAt) {
		return rows.get(rowAt);
	}

	@Override
	public int count() {
		return rows.size();
	}

	@Override
	public String toString() {
		return "Table{" +
				"rows=" + rows +
				", columns=" + columns +
				'}';
	}

	public Columns columns() {
		return columns;
	}

	public static class Builder {

		private final Columns columns;

		private final List<ColumnDrivenRow> rows;

		public Builder(String[] columnsAsText) {
			this(new Columns(columnsAsText));
		}

		public Builder(Columns columns) {
			this.columns = columns;
			rows = new ArrayList<>();
		}

		public Builder addRow(String[] rowValues) {
			rows.add(new ColumnDrivenRow(columns, rowValues));
			return this;
		}

		public SimpleTable build() {
			// FIXME 2021/1/15  wait for me!!!    always returns the same product
			return new SimpleTable(columns, rows);
		}
	}
}
